package utils

import (
	"navi-mumbai/common/key/dbkey"
	"navi-mumbai/common/xerr"
	"time"
)

// ParseTimeByString 根据时间字符串格式，转成time.Time
func ParseTimeByString(from string, format string) (*time.Time, error) {
	if from == "" || format == "" {
		return nil, xerr.NewGrpcErrCodeMsg(xerr.ParseTimeError, "time is nil")
	}
	var t time.Time
	loc, _ := time.LoadLocation(dbkey.DateTimeZone)
	t, err := time.ParseInLocation(format, from, loc)
	if err != nil {
		return nil, xerr.NewGrpcErrCodeMsg(xerr.ParseTimeError, err.Error())
	}
	return &t, nil
}
